const app = getApp()
var util = require('../../../../utils/util.js');
Page({
    data: {
        imgList: [],
        time: '',
        type: null
    },
    bindTimeChange(e) {
        this.setData({
            chooseTime: e.detail.value
        })
    },
    bindDateChange(e) {
        this.setData({
            chooseDate: e.detail.value
        })
    },
    //选择类型
    bindStartChange(e) {
        this.setData({
            start: this.data.type[e.detail.value]
        })

    },
    bindEndChange(e) {
        this.setData({
            end: this.data.type[e.detail.value]
        })

    },

    //获取输入内容
    get_desc(event) {
        this.data.desc = event.detail.value
    },

    get_start(event) {
        this.data.start = event.detail.value
    },
    get_end(event) {
        this.data.end = event.detail.value
    },

    get_QQ(event) {
        this.data.qq = event.detail.value
    },
    get_wx(event) {
        this.data.weixin = event.detail.value
    },
    get_num(event) {
        this.data.num = event.detail.value
    },
    get_phone(event) {
        this.data.phone = event.detail.value
    },
    onLoad: function (options) {
        var that = this;
        this.setData({
            goodName: options.goodName,
            price: options.price,
            spId: options.id
        })
        wx.request({
            url: app.globalData.baseUrl + 'api/spots/v1/wx/getAll',
            method: 'POST',
            data: {
                cId: options.id
            },
            success(res) {
                that.setData({
                    spot: res.data[0]
                })
            }
        })
    },
    //发布
    publish() {
        var that = this;

        var phone = this.data.phone;
        var weixin = this.data.weixin

        if (phone != null) {
            if (phone.length < 11 && phone.length > 0) {
                wx.showToast({
                    icon: "none",
                    title: '手机号码无效'
                })
                return
            }
        }
        if (!weixin) {
            wx.showToast({
                icon: "none",
                title: '姓名为空'
            })
            return
        }


        wx.showToast({
            title: '下单中...',
            icon: 'loading',
            duration: 2000,
            mask: true,
        })
        wx.request({
            url: app.globalData.baseUrl + 'api/orders/v1/wx/addOrUpdate',
            method: 'POST',
            data: {
                // 备注
                cNode: that.data.desc,
                // 姓名
                cName: that.data.weixin,
                // 电话
                cPhone: that.data.phone,
                // 订单时间
                dTime: new Date(),
                // 订单状态
                nStatus: 0,
                // 头像
                cIcon: app.globalData.userInfo.cIcon,
                // 昵称
                cNickName: app.globalData.userInfo.cNickName,
                // 景点名称
                cSpotName: this.data.spot.cName,
                // 商品价格
                dPrice: this.data.price,
                //商品名称
                cGoodName: this.data.goodName,
                // 商品id
                cJdspId: this.data.spot.cId,
                // 用户id
                cOpenId: app.globalData.openid
            },
            success(res) {
                wx.navigateBack({
                    delta: 0,
                    success() {
                        wx.showToast({
                            title: '购买成功',
                        })
                    }
                })
            }
        })
        // wx.cloud.database().collection('travel_good_orders').add({
        //     data: {
        //         // 备注
        //         note: that.data.desc,
        //         // 姓名
        //         name: that.data.weixin,
        //         // 电话
        //         phone: that.data.phone,
        //         // 订单时间
        //         time: util.formatTime(new Date()),
        //         // 订单状态
        //         status: 0,
        //         // 头像
        //         faceImg: app.globalData.userInfo.avatarUrl,
        //         // 昵称
        //         nickName: app.globalData.userInfo.nickName,
        //         // 景点名称
        //         spotName: this.data.spot.cName,
        //         // 商品价格
        //         price: this.data.price,
        //         //商品名称
        //         goodName: this.data.goodName, 
        //         // 商品id
        //         goodId: this.data.spot.cId, //ID
        //     }
        // }).then(res => {
        //     console.log(res)
        //     wx.navigateBack({
        //         delta: 0,
        //         success() {
        //             wx.showToast({
        //                 title: '购买成功',
        //             })
        //         }
        //     })

        // })
    },





})